package com.tjn.methods;

/**
 * @author 陶镓妮
 * @version 1.0
 */
public class ThreadMethod01 {
    public static void main(String[] args) throws InterruptedException {
        Method method = new Method();
        Thread thread = new Thread(method);
        thread.setName("tjn");//setName()设置线程名称

        thread.setPriority(Thread.MIN_PRIORITY);//setPriority()设置线程优先级
        thread.start();//start()启动线程

        System.out.println("优先级为" + thread.getPriority());//getPriority()获取线程优先级

        Thread.sleep(10000);
        thread.interrupt();//interrupt()中断线程
    }
}
class Method implements Runnable {
    @Override
    public void run() {
        while( true){
            for (int i = 0; i < 100; i++) {
                System.out.println(Thread.currentThread().getName() + "吃包子。。" + i);//getName()获取线程名称
            }
            System.out.println(Thread.currentThread().getName() + "休息一会");
            try {
                Thread.sleep(20000);//sleep()使线程进入休眠
            } catch (InterruptedException e) {
                System.out.println(Thread.currentThread().getName() + "被interrupt(中断)了");
            }
        }

    }
}